LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-10-2006, 04:31 AM   #1
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Rep: Reputation: 16
cat [file] | grep --- trouble


hey all,


quick little problem here, i have a log from my IRC channel, i want to use CAT on it for specific users for example

cat [logfile] | grep "username"

but the problem im getting is that the usernames are wrapped in < >'s

what would i need to do to get cat or grep to ignore the < >'s and just treat them as part of a word?

ive tried wrapping `word` "word" and 'word' and I still get nothing.

any help is appreciated.

Matty G
 
Old 03-10-2006, 04:59 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Quote:
Originally Posted by bob_man_uk
but the problem im getting is that the usernames are wrapped in < >'s

what would i need to do to get cat or grep to ignore the < >'s and just treat them as part of a word?
I don't get it; isn't this what grep usually does? Can you give an example and show us the exact commands?
 
Old 03-10-2006, 05:08 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by bob_man_uk
Code:
cat [logfile] | grep "username"
can be simplified to
Code:
grep username logfile
and as already stated, doesn't choke on "<>".
 
Old 03-10-2006, 05:12 AM   #4
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
seem to have it now, i havent changed the code or anything, hmm,

thanks anyway

Matty G
 
Old 03-10-2006, 05:15 AM   #5
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by jlliagre
can be simplified to
Code:
grep username logfile
and as already stated, doesn't choke on "<>".
but that would search for the username on every line,

i only want to bring back lines by specific users

E.G.

grep for bobman brings back sum 400 lines

grep for <bobman> brings back some 200 lines +/- 2 or 3 lines where someone will have quoted my own words,

got it sorted now anyway, i think i may have been telling cat to look at the wrong log file,

thanks again

Matty G
 
Old 03-10-2006, 05:21 AM   #6
sambyte
Member
 
Registered: Feb 2006
Distribution: Redhat 9
Posts: 38

Rep: Reputation: 15
Hi,
pls try out this command and see if it answers your query

# cat [logfile] | grep --color "[<]"

Pls see if it works or not....
 
Old 03-10-2006, 05:25 AM   #7
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
ok, sorry for the 3rd post but I have another question

I want to tail this log file and find the last 100 lines a user wrote (using <>'s again im afraid)

if i use

tail -100 "logfile" | grep "<bobman>"

it only brings back <bobman> from the last 100 lines, which thinking about it, is what it should do, what other ways should i go about pulling the last 100 lines of <bobman> from the log file?

Last edited by bob_man_uk; 03-10-2006 at 05:28 AM.
 
Old 03-10-2006, 05:27 AM   #8
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by sambyte
Hi,
pls try out this command and see if it answers your query

# cat [logfile] | grep --color "[<]"

Pls see if it works or not....

yes it works all too well, it pulls every line form the log file,

viva la ctrl+c

 
Old 03-10-2006, 05:39 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by bob_man_uk
ok, sorry for the 3rd post but I have another question

I want to tail this log file and find the last 100 lines a user wrote (using <>'s again im afraid)

if i use

tail -100 "logfile" | grep "<bobman>"

it only brings back <bobman> from the last 100 lines, which thinking about it, is what it should do, what other ways should i go about pulling the last 100 lines of <bobman> from the log file?
Try this:

Code:
grep "<bobman>" logfile | tail -100
 
Old 03-10-2006, 05:40 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You can grep then use tail to get the last 100 entries for a person.
grep "<bob>" logfile | tail -n 100
 
Old 03-10-2006, 05:42 AM   #11
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
ahh, switch them round...

i see, thats how it is, is it?

excelent, thanks guys.

EDIT - i get this

grep: writing output: Invalid argument

Last edited by bob_man_uk; 03-10-2006 at 05:47 AM.
 
Old 03-10-2006, 05:56 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You got this error while running which command ?

Last edited by jlliagre; 03-10-2006 at 05:59 AM.
 
Old 03-10-2006, 06:05 AM   #13
bob_man_uk
Member
 
Registered: Jul 2003
Location: Malta
Distribution: Ubuntu/Windows/Mac
Posts: 83

Original Poster
Rep: Reputation: 16
I run this

grep "<bob_man>" "#devhardware.GoodChatting.com.log" | tail -n 50

ok, ok i quess i will need to come clean here,

Im using ports of unix tools to do this on my home pc which.... is windows XP,

forget it, i guess i could knife and fork it by

cat logfile | grep username > username.txt

then tail the last 20 lines or something.

thanks all the same.

Matty G
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question About Cat And Grep George2 Linux - Software 10 03-09-2006 03:33 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 08:10 AM
bash: how to edit cat <filename> | grep <keyword> feature? sirpelidor Linux - Software 2 06-20-2005 02:00 PM
logrotate log files - keeping in order when using grep or cat and bash dmellem Linux - Software 6 02-11-2005 01:05 PM
output to a file - cat? grep? Godsmacker777 Linux - Newbie 6 12-08-2004 10:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration